
<#include "/base/common/head.html"/>
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
		        		
			            	<span class="search_item">
				            	<span class="item_text">系统标识: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name="system" id="system" value=""/>
				            	</span>    
				            </span>
		        		
			            	<span class="search_item">
				            	<span class="item_text">编号: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name=code id="code" value=""/>
				            	</span>    
				            </span>
		        		
			            	<span class="search_item">
				            	<span class="item_text">名称: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name="name" id="name" value=""/>
				            	</span>    
				            </span>
		        		
        </div>
        <div style="text-align: left; margin:6px;">
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">详情</a>
            <div id="searchBtnWrap" style="float:right; padding-right:40px;">
                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch()">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
            
        </div>
    </div>
    

<script type="text/javascript">

//数据表格初始化参数
var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,
    	url:'listData',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 20,
    	pagination:true,
    	//fitColumns:true,
    	striped:true,
    	multiSort:true,
    	singleSelect: false,
		ctrlSelect : true,
        queryParams: zcurdGetParam(),
        onDblClickRow:function(index, row){viewData(row.id);},
        
        columns: [[
		         {field:'id', checkbox:true}
	           	 ,{field:'system', title: '系统标识（system）', width:120, align:'center'}
	           	 ,{field:'code', title: '编号', width:100, align:'center'}
	           	 ,{field:'name', title: '名称', width:200, align:'center'}
	           	 ,{field:'value', title: '参数值', width:120, align:'center'}
	           	 ,{field:'group', title: '分组', width:100, align:'center'}
	           	 ,{field:'editor', title: '编辑器', width:100, align:'center'}
	           ]],
	      loadFilter: function(data) {
	        	   if(data.result && data.result == 'fail') {	//失败时，错误消息提示
	        		   showWarnMsg(data.msg);
	        		   return {};
	        	   }else {
	        		   return data;
	        	   }
	           }           
	};


var datagrid = $("#dg"); //数据表格

$(function() {
	datagrid.datagrid(dgOptions); //绘制数据表格
});

//查询
function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", param)
}

//获取查询参数
function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	//console.log(param);
	return param;
}

var initPara = zcurdGetParam(); //初始化参数，主要目的是保存一些隐藏条件

//增加
function add() {
	top.window.subPage.loadCurrDatagrid = function() { //设置成功后的回调方法
		datagrid.datagrid("load");
	}
	top.openWindow("增加", getCurrUrl("addPage") + "?" + $.param(initPara), {size: '400x360'});
}

//修改
function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		datagrid.datagrid("reload");
	}
	top.openWindow("编辑", getCurrUrl("updatePage") + "?id=" + id, {size: '400x360'});
}

//详情
function detail() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	top.openWindow_view("详情", getCurrUrl("detailPage") + "?id=" + id, {size: '400x330'});
}

//双击打开查看
function viewData(id) {
	top.openWindow_view("详情", getCurrUrl("detailPage") + "?id=" + id, {size: '400x330'});
}

//删除
function del() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据");
		return;
	}
	confirmMsg("确认删除?", function() {
		$.post(getCurrUrl("delete"), {ids: ids.join(",")}, function(data) {
			
			if("01" == data.code){//成功
				datagrid.datagrid("reload");
				showMsg(data.msg); //显示消息
			}else if("04" == data.code){//失败
				showErrorMsg(data.msg); //显示错误消息
			}
			
		});
	});
}

//导出（未实现）
function exportCsv() {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sortName = option.sortName;
	param.sortOrder = option.sortOrder;
	window.location.href = "exportCsv?" + $.param(param);
}


/**
 * 打开子页（右侧，暂未用上）
 */
var _openSubPageFlag = false;
function _openSubPage(pageUrl) {
	if(!_openSubPageFlag) {
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 600);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}

//扩展js
//格式化类型对象的输出
function formatType(value)
{
	return value.name;
};


function formatResultType(value)
{
	if(value.code=='01')
	{
		return value.name;
	}
	else
	{
		return "<span style='color:#ff0000'>"+value.name+"</span>";
	}
};


</script>

<#include "/base/common/dialogWindow.html"/>
<#include "/base/common/foot.html"/>
